from django.db import models
from utils.BaseModel import BaseModel

# Create your models here.
#课程分类模型
class CategoryModel(BaseModel):
    name = models.CharField(max_length=32,verbose_name="课程分类名称")
    parent= models.ForeignKey("self",null=True,on_delete=models.CASCADE,verbose_name="父级分类",related_name="son")
    recommend=models.BooleanField(default=False,verbose_name="是否推荐")
    ishot=models.BooleanField(default=False,verbose_name="是否热门")
    isgood=models.BooleanField(default=False,verbose_name="是否精品")
    class Meta:
        db_table = "fgcategory"
    def __str__(self):
        return self.name


#老师模型
class TeacherModel(BaseModel):
    name = models.CharField(max_length=32,verbose_name="老师名称")
    image = models.ImageField(upload_to="teacher",verbose_name="老师头像")
    jobtitle = models.CharField(max_length=32,verbose_name="老师职称")
    intro = models.TextField(verbose_name="老师简介")
    sales=models.IntegerField(verbose_name="销量")
    class Meta:
        db_table = "fgteacher"
    def __str__(self):
        return self.name
#LEVEL_CHOICES=((0,'初级'),(1,'中级'),(2,'高级'))
#课程模型
class CourseModel(BaseModel):
    name = models.CharField(max_length=32,verbose_name="课程名称")
    image = models.ImageField(upload_to="course",verbose_name="课程图片")
    price = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="课程价格")
    category = models.ForeignKey("CategoryModel",on_delete=models.CASCADE,verbose_name="课程分类")
    teacher = models.ForeignKey("TeacherModel",on_delete=models.CASCADE,verbose_name="授课老师")
    intro = models.TextField(verbose_name="课程简介")
    level=models.CharField(max_length=32,verbose_name="课程难度", choices=((0,'初级'),(1,'中级'),(2,'高级')),default=0)
    numbers= models.IntegerField(verbose_name="课程人数")
    is_home=models.BooleanField(verbose_name="是否推荐",default=True)
    video=models.CharField(verbose_name="视频",max_length=200,default='http://127.0.0.1:8000/uploads/course/video/1.mp4')
    class Meta:
        db_table = "fgcourse"
    def __str__(self):
        return self.name
